package com.example.databindingdemo;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.example.databindingdemo.databinding.RyitemBinding;

import java.util.ArrayList;
import java.util.List;

public class RyAdapter extends RecyclerView.Adapter<RyAdapter.MyViewHolder> {
    List<Idol> idols =new ArrayList<>();

    public RyAdapter(List<Idol> idols) {
        this.idols = idols;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
       RyitemBinding ryitemBinding =  DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()),R.layout.ryitem,parent,false);
        return new MyViewHolder(ryitemBinding);
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        Idol idol = idols.get(position);
        holder.ryitemBinding.setIdol(idol);
    }

    @Override
    public int getItemCount() {
        return idols.size();
    }

    static class MyViewHolder extends RecyclerView.ViewHolder{
         private  RyitemBinding ryitemBinding;
        public MyViewHolder(@NonNull RyitemBinding itemView) {
            super(itemView.getRoot());
            ryitemBinding = itemView;
        }
    }
}
